//
//  HouseFilterView.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/2.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "HouseFilterView.h"

@implementation HouseFilterView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initControl];
        
        [self setTime:@"04.03-04.05"];
        [self setAddress:@"大亚湾"];
    }
    
    return self;
}

- (void)initControl{
    
    self.backgroundColor = [UIColor whiteColor];
    
    float btnWidth = self.frame.size.width/3;
    float btnHeight = self.frame.size.height;
    
    for (int i=0; i<3; i++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitleColor:kMainOriginColor forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.tag = 100+i;
        if (i==1) {
            [button setTitle:@"筛选" forState:UIControlStateNormal];
        }
        [self addSubview:button];
        [button makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(btnWidth));
            make.height.equalTo(@(btnHeight));
            make.left.equalTo(@(i*btnWidth));
            make.top.equalTo(@0);
        }];
        WeakObj(self)
        [button buttonClick:^{
           
            if ([selfWeak.delegate respondsToSelector:@selector(HouseFilterClicked:)]) {
                [selfWeak.delegate HouseFilterClicked:button.tag-100];
            }
            
        }];
        
        UIImageView *iconImgView = [[UIImageView alloc]init];
        iconImgView.image = [UIImage imageNamed:@"baseinf_location_no"];
        [button addSubview:iconImgView];
        [iconImgView makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(i==0?5:20));
            make.width.height.equalTo(@20);
            make.centerY.equalTo(button.centerY);
        }];
        if (i<2) {
            UIView *lineView = [[UIView alloc]init];
            lineView.backgroundColor = kLineColor;
            [button addSubview:lineView];
            [lineView makeConstraints:^(MASConstraintMaker *make) {
                make.right.top.bottom.equalTo(@0);
                make.width.equalTo(@0.5);
            }];
        }
    }
}

- (void)setTime:(NSString*)str{
    
    UIButton *button = (UIButton*)[self viewWithTag:100];
    [button setTitle:str forState:UIControlStateNormal];
}

- (void)setAddress:(NSString*)str{
    UIButton *button = (UIButton*)[self viewWithTag:102];
    [button setTitle:str forState:UIControlStateNormal];
}

@end
